/**
 * LUTube Shortcode javascript
 * Plugin URI: http://code.google.com/p/lutube-shortcode-plugin/
 * jQuery used to embed LUTube video using a wordpress shortcode
 * @author Peter Edwards
 * @version: 0.2
 */

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
jQuery(function($){
	if ($('.lutube-video-wrap').length) {
		var vid = document.createElement('video');
		if (vid) {
			/* browser supports video media element */
		    $('video').each(function(){
		    	/* get the video mime types */
			    var sourceTypes = [];
			    if ($('source', this).length) {
			        $('source', this).each(function(){
			    	    sourceTypes.push($(this).attr("type"));
			        });
			    } else {
			    	/* single sources - h.264 baseline or extended */
			    	if ($(this).attr("src").indexOf(".m4v") != -1) {
			    		/* baseline profile */
			    		sourceTypes.push('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
			    	} else {
			    		/*extended profile */
			    		sourceTypes.push('video/mp4; codecs="avc1.64001E, mp4a.40.2"');
			    	}
			    }
		        var canPlay = false;
			    for (i = 0; i < sourceTypes.length; i++) {
			    	if (vid.canPlayType(sourceTypes[i]) === "probably") {
			    		canPlay = true;
			    	}
			    }
			    if (!canPlay) {
			    	var flashObject = $('object', this).clone();
			    	$(this).replaceWith(flashObject);
			    }
		    });
		} else {
			/* browser doesn't support video media element - should fall back to flash/image */
			
		}
	}
});

